home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
M2Crypto
/
DSA.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
195 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import sys
import util
import BIO
import m2
class DSAError(Exception):
pass
m2.dsa_init(DSAError)
class DSA:
m2_dsa_free = m2.dsa_free
def __init__(self, dsa, _pyfree = 0):
self.dsa = dsa
self._pyfree = _pyfree
def __del__(self):
if getattr(self, '_pyfree', 0):
self.m2_dsa_free(self.dsa)
def __len__(self):
return m2.dsa_keylen(self.dsa)
def __getattr__(self, name):
if name in ('p', 'q', 'g', 'pub', 'priv'):
method = getattr(m2, 'dsa_get_%s' % (name,))
return method(self.dsa)
else:
raise AttributeError
def __setattr__(self, name, value):
if name in ('p', 'q', 'g'):
raise DSAError('set (p, q, g) via set_params()')
elif name in ('pub', 'priv'):
raise DSAError('generate (pub, priv) via gen_key()')
else:
self.__dict__[name] = value
def set_params(self, p, q, g):
m2.dsa_set_p(self.dsa, p)
m2.dsa_set_q(self.dsa, q)
m2.dsa_set_g(self.dsa, g)
def gen_key(self):
m2.dsa_gen_key(self.dsa)
def save_params(self, filename):
bio = BIO.openfile(filename, 'wb')
ret = m2.dsa_write_params_bio(self.dsa, bio._ptr())
bio.close()
return ret
def save_params_bio(self, bio):
return m2.dsa_write_params_bio(self.dsa, bio._ptr())
def save_key(self, filename, cipher = 'aes_128_cbc', callback = util.passphrase_callback):
bio = BIO.openfile(filename, 'wb')
ret = self.save_key_bio(bio, cipher, callback)
bio.close()
return ret
def save_key_bio(self, bio, cipher = 'aes_128_cbc', callback = util.passphrase_callback):
if cipher is None:
return m2.dsa_write_key_bio_no_cipher(self.dsa, bio._ptr(), callback)
else:
ciph = getattr(m2, cipher, None)
if ciph is None:
raise DSAError('no such cipher: %s' % cipher)
else:
ciph = ciph()
return m2.dsa_write_key_bio(self.dsa, bio._ptr(), ciph, callback)
def save_pub_key(self, filename):
bio = BIO.openfile(filename, 'wb')
ret = self.save_pub_key_bio(bio)
bio.close()
return ret
def save_pub_key_bio(self, bio):
return m2.dsa_write_pub_key_bio(self.dsa, bio._ptr())
def sign(self, digest):
return m2.dsa_sign(self.dsa, digest)
def verify(self, digest, r, s):
return m2.dsa_verify(self.dsa, digest, r, s)
def sign_asn1(self, digest):
return m2.dsa_sign_asn1(self.dsa, digest)
def verify_asn1(self, digest, blob):
return m2.dsa_verify_asn1(self.dsa, digest, blob)
def check_key(self):
return m2.dsa_check_key(self.dsa)
class DSA_pub(DSA):
def sign(self, *argv):
raise DSAError('DSA_pub object has no private key')
sign_asn1 = sign
def check_key(self):
return m2.dsa_check_pub_key(self.dsa)
save_key = DSA.save_pub_key
save_key_bio = DSA.save_pub_key_bio
def gen_params(bits, callback = util.genparam_callback):
dsa = m2.dsa_generate_parameters(bits, callback)
if dsa is None:
raise DSAError('problem generating DSA parameters')
return DSA(dsa, 1)
def set_params(p, q, g):
dsa = m2.dsa_new()
m2.dsa_set_p(dsa, p)
m2.dsa_set_q(dsa, q)
m2.dsa_set_g(dsa, g)
return DSA(dsa, 1)
def load_params(file, callback = util.passphrase_callback):
bio = BIO.openfile(file)
ret = load_params_bio(bio, callback)
bio.close()
return ret
def load_params_bio(bio, callback = util.passphrase_callback):
dsa = m2.dsa_read_params(bio._ptr(), callback)
if dsa is None:
raise DSAError('problem loading DSA parameters')
return DSA(dsa, 1)
def load_key(file, callback = util.passphrase_callback):
bio = BIO.openfile(file)
ret = load_key_bio(bio, callback)
bio.close()
return ret
def load_key_bio(bio, callback = util.passphrase_callback):
dsa = m2.dsa_read_key(bio._ptr(), callback)
if not dsa:
raise DSAError('problem loading DSA key pair')
return DSA(dsa, 1)
def load_pub_key(file, callback = util.passphrase_callback):
bio = BIO.openfile(file)
ret = load_pub_key_bio(bio, callback)
bio.close()
return ret
def load_pub_key_bio(bio, callback = util.passphrase_callback):
dsapub = m2.dsa_read_pub_key(bio._ptr(), callback)
if not dsapub:
raise DSAError('problem loading DSA public key')
return DSA_pub(dsapub, 1)